<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: Ankoder::CoreExtension::HashExtension</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">Ankoder::CoreExtension::HashExtension</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/lib/ankoder/ext_rb.html">
                lib/ankoder/ext.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000009">method_missing</a>&nbsp;&nbsp;
      <a href="#M000008">type_cast!</a>&nbsp;&nbsp;
      <a href="#M000007">underscore_keys!</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000009" class="method-detail">
        <a name="M000009"></a>

        <div class="method-heading">
          <a href="#M000009" class="method-signature">
          <span class="method-name">method_missing</span><span class="method-args">(m, *args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The hash keys are available by calling the method name &quot;key&quot;
</p>
<pre>
 h = {&quot;profile_id&quot; =&gt; 54, &quot;video_id&quot; =&gt; 12}
 h.profile_id
 =&gt; 54
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000009-source">
<pre>
    <span class="ruby-comment cmt"># File lib/ankoder/ext.rb, line 42</span>
42:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">m</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
43:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">to_s</span>
44:           <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">m</span>.<span class="ruby-identifier">to_s</span>]
45:         <span class="ruby-keyword kw">else</span>
46:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">NoMethodError</span>, <span class="ruby-node">&quot;undefined method `#{m.to_s}' for #{self.class}&quot;</span>
47:         <span class="ruby-keyword kw">end</span>
48:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000008" class="method-detail">
        <a name="M000008"></a>

        <div class="method-heading">
          <a href="#M000008" class="method-signature">
          <span class="method-name">type_cast!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Cast each value of the hash in the right format (integer, float, time,
boolean)
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000008-source">
<pre>
    <span class="ruby-comment cmt"># File lib/ankoder/ext.rb, line 24</span>
24:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">type_cast!</span>
25:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
26:           <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>].<span class="ruby-identifier">type_cast!</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
27:           <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>].<span class="ruby-identifier">to_i</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^[0-9]+$/</span>
28:           <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>].<span class="ruby-identifier">to_f</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^[0-9]+\.[0-9]+$/</span>
29:           <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>]) <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/[a-z]+ [a-z]+ [0-9]+ [0-9]{2}:[0-9]{2}:[0-9]{2} [a-z0-9\+]+ [0-9]{4}/i</span>
30:           <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;true&quot;</span>
31:           <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;false&quot;</span>
32:           <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator">==</span> {}
33:         <span class="ruby-keyword kw">end</span>
34:         <span class="ruby-keyword kw">self</span>
35:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000007" class="method-detail">
        <a name="M000007"></a>

        <div class="method-heading">
          <a href="#M000007" class="method-signature">
          <span class="method-name">underscore_keys!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Replace &quot;-&quot; by &quot;_&quot; in all keys of the hash
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000007-source">
<pre>
    <span class="ruby-comment cmt"># File lib/ankoder/ext.rb, line 14</span>
14:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">underscore_keys!</span>
15:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
16:           <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>].<span class="ruby-identifier">underscore_keys!</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
17:           <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">&quot;-&quot;</span>, <span class="ruby-value str">&quot;_&quot;</span>)] = <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>]
18:           <span class="ruby-identifier">delete</span>(<span class="ruby-identifier">k</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/-/</span>
19:         <span class="ruby-keyword kw">end</span>
20:         <span class="ruby-keyword kw">self</span>
21:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>